package com.ss.android.j;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.view.View;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.R;

public final class ClickableBackgroundCompat {
    static final class LOLLIPOPImpl extends KITKATImpl {
        LOLLIPOPImpl() {

        }

        public final int a(int arg2) {
            return c.a(arg2);
        }

        @SuppressLint(value = {"NewApi"})
        public final Drawable getDrawable(Context context, int drawableResId) {
            Drawable v0 = context == null || drawableResId <= 0 ? null : context.getDrawable(drawableResId);
            return v0;
        }

        public final Drawable getClickableDrawable(Context context, int arg3, boolean arg4) {
            Drawable drawable = c.getClickableBackgroundDrawable(context);
            if (drawable == null) {
                drawable = super.getClickableDrawable(context, arg3, arg4);
            }

            return drawable;
        }

        public final Drawable getClickableBorderLessDrawable(Context context, int arg3, boolean arg4) {
            Drawable drawable = c.getClickableBorderlessBackgroundDrawable(context);
            if (drawable == null) {
                drawable = super.getClickableBorderLessDrawable(context, arg3, arg4);
            }
            return drawable;
        }
    }

    static class KITKATImpl {
        KITKATImpl() {

        }

        public int a(int arg1) {
            return arg1;
        }

        public Drawable getClickableDrawable(Context context, int drawableResId, boolean arg4) {
            Drawable drawable = context == null ? null : ContextCompat.getDrawable(context, drawableResId);
            return drawable;
        }

        public Drawable getDrawable(Context context, int drawableResId) {
            Drawable drawable = context == null || drawableResId <= 0 ? null : context.getResources().getDrawable(drawableResId);
            return drawable;
        }

        public Drawable getClickableBorderLessDrawable(Context context, int arg3, boolean arg4) {
            return this.getDrawable(context, arg3);
        }
    }

    private static KITKATImpl IMPL = Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? new KITKATImpl() : new LOLLIPOPImpl();

    public static int getTheme(int arg1) {
        return IMPL.a(arg1);
    }

    public static void setClickableBorderlessBackground(View view) {
        if (view != null && (c.isAboveLOLLIPOP)) {
            UIUtils.setBackgroundDrawable(view, IMPL.getClickableBorderLessDrawable(view.getContext(), 0, false));
        }
    }

    public static void setClickableBackground(View view, boolean isNightMode) {
        if (view != null) {
            UIUtils.setBackgroundDrawable(view, IMPL.getClickableDrawable(view.getContext(), R.drawable.clickable_background, isNightMode));
        }
    }
}

